﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Micrhard.FMCG.Server.Interface;
using Micrhard.FMCG.Server.DataAccess;
using Micrhard.FMCG.Server.Models;
using Micrhard.FMCG.Server.DTO;

namespace Micrhard.FMCG.Server.Impl
{
    public class MyNoticeImpl : IMyNotice
    {
        public Microhard.Core.DBUtility.ExecutedResult Add(Models.NoticeModel model)
        {
            throw new NotImplementedException();
        }

        public Microhard.Core.DBUtility.ExecutedResult Update(Models.NoticeModel model)
        {
            throw new NotImplementedException();
        }

        public Microhard.Core.DBUtility.ExecutedResult Delete(List<Guid> ids)
        {
            throw new NotImplementedException();
        }

        public Microhard.Core.DBUtility.ExecutedResult Delete(Models.NoticeModel model)
        {
            throw new NotImplementedException();
        }

        public Models.NoticeModel GetModelByID(Guid id)
        {
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            var model = db.Notices.SingleOrDefault(c => c.NoticeID == id);
            if (model != null)
            {
                return model.ToModel();
            }
            return null;
        }

        public Models.NoticeModel GetModelByModel(Models.NoticeModel model)
        {
            throw new NotImplementedException();
        }

        public List<Models.NoticeModel> Query(Models.NoticeModel Model, int pageIndex, int pageSize, out int totalCount)
        {
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            IEnumerable<Notice> entities = from b in db.Notices
                                           from s in b.NoticeRecScopes
                                           where s.Employee.UserName == this.scope.CurrentUserName
                                           select b;
            totalCount = entities.Count();
            var pagedEntities = entities.OrderByDescending(p => p.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            if (pagedEntities != null && pagedEntities.Count > 0)
                return pagedEntities.Select(m => m.ToModel()).ToList();
            return new List<NoticeModel>();
        }

        public List<Models.NoticeModel> Query(Models.NoticeModel Model)
        {
            throw new NotImplementedException();
        }

        public Microhard.Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
